<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@include file="/include/nocache.jsp" %>
<html>
	<head>
		<title>URL收藏</title>
		<script type="text/javascript" src="${pageContext.request.contextPath}/script/jquery-1.9.1.min.js"></script>
		<style>
			.pagea {
				background: #f5f5f5;
				cursor: pointer;
				padding: 3px 8px;
				margin: 0 5px 0 0;
				text-decoration: none;
				text-align: center;
				font-family: tahoma, helvetica, arial;
				font-size: 12px;
				color:#000000;
				border: solid 1px #34638c;
			}
			
			.pageaselect {
				background: #34638c;
				cursor: pointer;
				padding: 3px 8px;
				margin: 0 5px 0 0;
				text-decoration: none;
				text-align: center;
				font-family: tahoma, helvetica, arial;
				font-size: 12px;
				color:#FFFFFF;
			}
			a{text-decoration: none;}
		</style>
	</head>
	<body>
		<table>
			<tr>
				<td valign="top">
					<table width="900" border="0" cellpadding="5" cellspacing="1" bgcolor="#007373" style="table-layout:fixed">
						<tr>
							<th nowrap bgcolor="#159AA2" style="overflow:hidden; text-overflow:ellipsis; color:#FFFFFF;" width="30"></th>
							<th nowrap bgcolor="#159AA2" style="overflow:hidden; text-overflow:ellipsis; color:#FFFFFF;" width="200">标题</th>
							<th nowrap bgcolor="#159AA2" style="overflow:hidden; text-overflow:ellipsis; color:#FFFFFF;" width="100">分类</th>
							<th nowrap bgcolor="#159AA2" style="overflow:hidden; text-overflow:ellipsis; color:#FFFFFF;" width="370">地址</th>
							<th nowrap bgcolor="#159AA2" style="overflow:hidden; text-overflow:ellipsis; color:#FFFFFF;" width="150">收藏时间</th>
							<th nowrap bgcolor="#159AA2" style="overflow:hidden; text-overflow:ellipsis; color:#FFFFFF;" width="50">操作</th>
						</tr>
						<s:iterator value="collectList" status="stat">
							<tr title="<s:property value="remark"/>">
								<td align="center" nowrap bgcolor="#E8FFFF" style="font-size:14px;overflow:hidden; text-overflow:ellipsis;"><s:property value="#stat.index+1"/></td>
								<td nowrap bgcolor="#E8FFFF" style="font-size:14px;overflow:hidden; text-overflow:ellipsis;"><a href="<s:property value="url"/>" target="_blank" title="<s:property value="urltitle"/>"><s:property value="urltitle"/></a></td>
								<td align="center" nowrap bgcolor="#E8FFFF" style="font-size:14px;overflow:hidden; text-overflow:ellipsis;"><s:property value="typeShow"/></td>
								<td nowrap bgcolor="#E8FFFF" style="font-size:14px;overflow:hidden; text-overflow:ellipsis;"><a href="<s:property value="url"/>" target="_blank" title="<s:property value="url"/>"><s:property value="url"/></a></td>
								<td align="center" nowrap bgcolor="#E8FFFF" style="font-size:14px;overflow:hidden; text-overflow:ellipsis;"><s:date format="yyyy-MM-dd HH:mm" name="createtime"/></td>
								<td align="center" nowrap bgcolor="#E8FFFF" style="font-size:14px;overflow:hidden; text-overflow:ellipsis;">
									<a href="javascript:;" onclick="deleteUrlCollect('<s:property value="id"/>')">删除</a>
								</td>
							</tr>
						</s:iterator>
							<tr title="<s:property value="remark"/>">
								<td align="center" colspan="6" nowrap bgcolor="#E8FFFF" style="font-size:14px;overflow:hidden; text-overflow:ellipsis;">
									<div id="page"></div>
								</td>
							</tr>
					</table>
				</td>
				<td valign="top"> 
					<form method="get" action="${pageContext.request.contextPath}/url.zhtml">
						<input type="text" style="width:120px" name="query" value="<s:property value="query"/>"/><br/>
						<input type="submit" value="搜索" style="width:120px"/>					
					</form>
				</td>
			</tr>
		</table>
		
		<script>
			function deleteUrlCollect(id){
				if(confirm("删除之后无法找回，确定要删除？")){
					var url="${pageContext.request.contextPath}/urlcollect/delete.zhtml?urlIds="+id+"&_rad="+new Date().getTime();
					$.get(url,function(data){
						window.location.reload();
					});
				}
			}
			
			function fixPage(){
				var initCount=5;
				var page=${page};
				page=page==0?1:page;
				var pageSize=${pageSize};
				var total=${total};
				var pageCount=Math.ceil(total/pageSize);
				var start=1;
				var end=pageCount;
				if(page<initCount){
					start=1;
				}else{
					start=initCount-4;
				}
				if((page+initCount)>pageCount){
					end=pageCount;
				}else{
					end=page+5;
				}
				var html="";
				if(page!=1){
					html=html+"<a href='?page="+(page-1)+"&query="+encodeURIComponent("<s:property value="query"/>")+"' class='pagea'>&lt;&lt;上一页</a>";
				}
				for(var i=start;i<=end;i++){
					if(i==page){
						html=html+"<a class='pageaselect'>"+i+"</a>";
					}else{
						html=html+"<a href='?page="+i+"&query="+encodeURIComponent("<s:property value="query"/>")+"' class='pagea'>"+i+"</a>";
					}
				}
				if(page!=pageCount){
					html=html+"<a href='?page="+(page+1)+"&query="+encodeURIComponent("<s:property value="query"/>")+"' class='pagea'>下一页&gt;&gt;</a>";
				}
				$("#page").html(html);		
			}
			fixPage();
		</script>
	</body>
</html>